package cn.net.isir.core;

import cn.net.isir.service.PermissionService;

import javax.annotation.Resource;

/**
 * @author liuxubo
 * @filename ShiroFilterChainDefinitions.java
 * @package cn.net.isir.core
 * @email lxb@isir.net.cn
 * @date 2018/11/27
 * @comment
 * @since 1.8
 */
public class ShiroFilterChainDefinitions {
    // 声明log4j日志
    private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(ShiroFilterChainDefinitions.class);

    @Resource
    private PermissionService permissionService;

    public String loadFilterChainDefinitions() {
        logger.info("-----------------loadFilterChainDefinitions---------------------------");
        logger.info(permissionService.selectList(null).size());
        StringBuilder sb = new StringBuilder();
        sb.append("/login.html").append(" = ").append("anno").append("\r\n");
        sb.append("/index.html").append(" = ").append("anno").append("\r\n");
        sb.append("/unauthorized.html").append(" = ").append("anno").append("\r\n");
        sb.append("/ticket/**").append(" = ").append("anon").append("\r\n");
        sb.append("/minip/**").append(" = ").append("anon").append("\r\n");
        sb.append("/media/**").append(" = ").append("anon").append("\r\n");
        sb.append("/manage/login").append(" = ").append("anon").append("\r\n");
        sb.append("/manage/loginget").append(" = ").append("anon").append("\r\n");
        sb.append("/manage/logout").append(" = ").append("authc").append("\r\n");
        sb.append("/manage/register").append(" = ").append("anon").append("\r\n");
        sb.append("/menu/**").append(" = ").append("authc").append("\r\n");
        sb.append("/page/login.jsp").append(" = ").append("anon").append("\r\n");
        sb.append("/page/register/*").append(" = ").append("anon").append("\r\n");
        sb.append("/page/index.jsp").append(" = ").append("authc").append("\r\n");
        sb.append("/page/pp.jsp").append(" = ").append("perms[abc:def]").append("\r\n");
        sb.append("/page/addItem*").append(" = ").append("authc,roles[数据管理员]").append("\r\n");
        sb.append("/page/updateItem*=authc,perms[user:create]");
        sb.append("/test/**").append(" = ").append("authc,rest").append("\r\n");
        sb.append("/**").append(" = ").append("authc,perms[openNotExist1,openNotExist2]").append("\r\n");
        return sb.toString();
    }
}
